package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Department;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.IDepartmentService;
import cn.wolfcode.rbac.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Description TODO
 * @ClassName DepartmentController
 * @Author luhui
 * @date 2020.06.13 12:58
 * @version: 1.0
 */

@Controller
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @RequestMapping("/department/list")
    @RequiredPermission(values = {"部门列表","department:list"})
    public String list(Model model, QueryObject queryObject){
        model.addAttribute("result",departmentService.query(queryObject));
        return "department/list";
    }

    @RequestMapping("/department/delete")
    @RequiredPermission(values = {"部门删除","department:delete"})
    public String delete(Long id){
        departmentService.delete(id);
        return "redirect:/department/list.do";
    }

    @RequestMapping("/department/input")
    @RequiredPermission(values = {"部门编辑","department:input"})
    public String input(Model model,Long id){
        if (id != null){
            model.addAttribute("entity",departmentService.get(id));
        }
        return "department/input";
    }

    @RequestMapping("/department/saveOrUpdate")
    @RequiredPermission(values = {"部门新增或删除","department:saveOrUpdate"})
    public String saveOrUpdate(Department department){
        departmentService.saveOrUpdate(department);
        return "redirect:/department/list.do";
    }
}